package service.impl;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import domain.User;
import service.UserService;

import java.util.List;

/**
 * @author HLF
 * @version V1.0
 * @package service.impl
 * @date 2021/10/30 19:57
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    @Override
    public int registUser(User user) {
        int insert = 0;
        User user2 = userDao.selectUserById(user.getId());
        if (user2 == null) {
            insert = userDao.insertUser(user);
        }
        return insert;
    }

    @Override
    public User loginUser(User user) {
        return userDao.selectUserByIdAndPassword(user);
    }

    @Override
    public User existsUser(Integer id) {
        return userDao.selectUserById(id);
    }

    @Override
    public int updateUser(User user) {
        int i = userDao.updateUser(user);
        return i;
    }

    @Override
    public List<User> selectAllUsers() {
        List<User> users = userDao.selectAllUsers();
        return users;
    }

    @Override
    public int deleteUser(Integer id) {
        int i = userDao.deleteUserById(id);
        return i;
    }
}
